package twel.probenprophet.helden.heroes.helden5.jaxb;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import twel.probenprophet.base.enums.Attribute;

@XmlAccessorType(XmlAccessType.FIELD)
public class Hero {

	@XmlAttribute
	private String name;

	@XmlElement(name = "eigenschaften")
	@XmlJavaTypeAdapter(value = AttributeMapAdapter.class)
	private Map<Attribute, Integer> attributes;

	@XmlElementWrapper(name = "zauberliste")
	@XmlElement(name = "zauber")
	private Collection<SpellSkill> spellSkills;

	public Hero() {
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Map<Attribute, Integer> getAttributes() {
		return attributes;
	}

	public void setAttributes(Map<Attribute, Integer> attributes) {
		this.attributes = attributes;
	}

	public Collection<SpellSkill> getSpellSkills() {
		return spellSkills;
	}

	public void setSpellSkills(Collection<SpellSkill> spellSkills) {
		this.spellSkills = spellSkills;
	}

	@Override
	public String toString() {
		return name;
	}

	public static class Builder {

		private String name;
		private Map<Attribute, Integer> attributes = new HashMap<Attribute, Integer>();
		private Collection<SpellSkill> spellSkills;

		public Hero build() {
			Hero hero = new Hero();

			hero.setName(name);
			hero.setAttributes(attributes);
			hero.setSpellSkills(spellSkills);

			return hero;
		}

		public Builder setName(String name) {
			this.name = name;
			return this;
		}

		public Builder setAttributes(Map<Attribute, Integer> attributes) {
			this.attributes = attributes;
			return this;
		}

		public Builder setSpellSkills(Collection<SpellSkill> spellSkills) {
			this.spellSkills = spellSkills;
			return this;
		}
	}
}
